import React, {useRef} from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import ProTable from '@ant-design/pro-table';
import { getOvertimeApplyList} from '../service';
import moment from 'moment';
import {Tooltip,Tag} from 'antd';
import {overtimeType} from "@/utils/constant";

const TableList = () => {
  const actionRef = useRef();

  const columns = [
    {
      title: '申请时间',
      dataIndex: 'createTime',
      hideInSearch: true,
      render: (text) =>{
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : ''
      }
    },
    {
      title: '申请人',
      dataIndex: 'oprationName',
    },
    {
      title: '申请人工号',
      hideInSearch: true,
      dataIndex: 'oprationId',
    },
    {
      title: '加班人员',
      dataIndex: 'subEmployeeOverworkEntities',
      hideInSearch: true,
      align:'center',
      width: 300,
      render:(text)  => (
        <>
          {text?.map((item,index) => {
              let temp = item.corpName + "-" + item.orgName + "-" + item.employeeName + "-" + item.employeeId;
              return  <Tooltip overlayStyle={{maxWidth: 500}} title={temp} key={index}>
                <Tag style={{marginTop:'5px'}} color={'#68b377'} key={index}>
                  {item.employeeName}
                </Tag>
              </Tooltip>
            }
          )}
        </>
      )
    },
    {
      title: '加班类型',
      dataIndex: 'overworkType',
      hideInSearch: true,
      render: (text) => {
        return overtimeType.find((item) => item.value === text).label;
      },
    },
    {
      title: '加班开始日期',
      dataIndex: 'overworkBeginTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD HH:mm') : '';
      },
    },
    {
      title: '加班结束日期',
      dataIndex: 'overworkEndTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD HH:mm') : '';
      },
    },
    {
      title: '加班状态',
      dataIndex: 'satus',
      hideInSearch: true,
      valueEnum: {
        1: { text: '待发起', status: 'Default' },
        2: { text: '审批中', status: 'Processing' },
        3: { text: '审批通过', status: 'Success' },
        4: { text: '审批拒绝', status: 'Warning' },
      },
    },
    {
      title: '加班说明',
      dataIndex: 'overworkRemark',
      hideInSearch: true,
      ellipsis:true,
      width: 200
    },
    {
      title: '操作',
      dataIndex: 'option',
      valueType: 'option',
      align:'center',
      render: (item, record) => (
        <>
          {(record.satus !== 1 && record.checkUrl) && <><a onClick={() => window.open(record.checkUrl)}>审批详情</a></>}
        </>
      ),
    }
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        request={(params) => getOvertimeApplyList(params)}
        columns={columns}
      />
    </PageHeaderWrapper>
  )
};

export default (TableList);
